package leetcode;

import java.util.*;

class Employee {
    public int id;
    public int importance;
    public List<Integer> subordinates;
};
public class LeetCodeMain67 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        while (in.hasNext()){
            String str1=in.next();
            String str2=in.next();
            String str3=in.next();
            StringBuffer min1=new StringBuffer();
            StringBuffer max=new StringBuffer();
            StringBuffer min2=new StringBuffer();
            if (str1.compareTo(str2)>=0){
                if (str1.compareTo(str3)>=0){
                    max.append(str1);
                    min2.append(str3);
                    min1.append(str2);
                }else {
                    max.append(str3);
                    min2.append(str1);
                    min1.append(str2);
                }
            }else {
                if (str2.compareTo(str3)>=0){
                    max.append(str2);
                    min2.append(str3);
                    min1.append(str1);
                }else {
                    max.append(str3);
                    min1.append(str1);
                    min2.append(str2);
                }
            }
        }
    }
    public int Add(int num1,int num2) {
        while(num2!=0){
            int temp = num1^num2;
            num2 = (num1&num2)<<1;
            num1=temp;
        }
        return num1;
    }
    int[][] nextP={{1,0},{-1,0},{0,1},{0,-1}};
    public void solve(char[][] board) {
        if (board==null||board.length==0){
            return;
        }
        int row = board.length;
        int col = board[0].length;
        for (int i = 0; i < col; i++) {
            if (board[0][i]=='O'){
                DFS(board,row,col,0,i);
            }
            if (board[row-1][i]=='O'){
                DFS(board,row,col,row-1,i);
            }
        }
        for (int i = 0; i < row; i++) {
            if (board[i][0]=='O'){
                DFS(board,row,col,i,0);

            }if (board[i][col-1]=='O'){
                DFS(board,row,col,i,col-1);
            }
        }
        for (int i = 0; i < row; ++i)
        {
            for (int j = 0; j < col; ++j)
            {
                if (board[i][j] == 'A')
                    board[i][j] = 'O';
                else if (board[i][j] == 'O')
                    board[i][j] = 'X';
            }
        }

    }

    public void DFS(char[][] board,int row,int col,int curX,int curY){
        board[curX][curY]='A';
        for (int i = 0; i < 4; i++) {
            int newX=curX+nextP[i][0];
            int newY=curY+nextP[i][1];
            if (newX<0||newY<0||newX>=row||newY>=col){
                continue;
            }
            if (board[newX][newY]=='O'){
                DFS(board, row, col, newX, newY);
            }
        }
    }
    public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
        int color=image[sr][sc];
        DFS1(image,sr,sc,newColor,color);
        return image;
    }
    public void DFS1(int[][] image, int sr, int sc, int newColor, int oldColor){
        if (sr<0||sc<0||sc>=image[0].length||sr>=image.length){
            return;
        }
        if (image[sr][sc]==newColor||image[sr][sc]!=oldColor){
            return;
        }
        image[sr][sc]=newColor;
        DFS1(image, sr+1, sc, newColor, oldColor);
        DFS1(image, sr-1, sc, newColor, oldColor);
        DFS1(image, sr, sc+1, newColor, oldColor);
        DFS1(image, sr, sc-1, newColor, oldColor);
    }
    public int dfs(Map<Integer,Employee> info, int id){
        Employee employee=info.get(id);
        int sum=employee.importance;
        for (int subId:employee.subordinates) {
            sum+= dfs(info,subId);
        }
        return sum;
    }
    public int getImportance(List<Employee> employees, int id) {
        if (employees.isEmpty()){
            return 0;
        }
        HashMap<Integer,Employee> map=new HashMap<>();
        for (Employee employee:employees) {
            map.put(employee.id,employee);
        }
        return dfs(map,id);
    }
    public int maxEvents(int[][] events) {
        Arrays.sort(events,(o1, o2) -> o1[1]-o2[1]);
        int count=0;
        int dist=0;
        for (int i = 1; i < events.length; i++) {
            if (events[i][0]>=events[dist][1]){
                count++;
                dist=i;
            }
        }
        return count;
    }
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals,(o1, o2) -> o1[1]-o2[1]);
        int count=0;
        int dist=intervals[0][1];
        for (int i = 1; i < intervals.length; i++) {
            if (dist>intervals[i][0]){
                count++;
            }else {
                dist=intervals[i][1];
            }
        }
        return count;
    }

    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int number = scanner.nextInt();

        int[][] act = new int[number][2];
        int idx = 0;
        for (int i = 0; i < act.length; ++i)
        {
            act[i][0] = scanner.nextInt();
            act[i][1] = scanner.nextInt();
        }
        Arrays.sort(act, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[0]==o2[0]){
                    return o1[1]-o2[1];
                }
                return o1[0]-o2[0];
            }
        });

//按照活动截止时间从小到大排序
//        Arrays.sort(act, new myComparator());
//        int ret = greedyActivitySelector(act);
//        System.out.println(ret);
    }
    public static int solve(int money, int[][] moneyCount){
        int num=0;
        for (int i = moneyCount.length-1; i >= 0; i--) {
            int c=money/moneyCount[i][0];
            c=Math.min(c,moneyCount[i][1]);
            num+=c;
            money-=c*moneyCount[i][0];
        }
        if (money>0){
            return -1;
        }
        return num;
    }
    public static void main1(String[] args) {
//存放纸币与数量: first:纸币，second:数量
        int[][] moneyCount = { { 1, 3 }, { 2, 1 }, { 5, 4 }, { 10, 3 }, { 20, 0 }
                ,{50, 1}, { 100, 10 } };
        Scanner scanner = new Scanner(System.in);
        int money;
        System.out.println("请输入要支付的钱");
        money = scanner.nextInt();
        int res = solve(money, moneyCount);
        if (res != -1)
            System.out.println(res);
        else
            System.out.println("No");
    }

    public boolean canJump(int[] nums) {
        if (nums.length==1){
            return true;
        }
        int pos=nums.length-1;
        int max=0;
        for (int i = 0; i <= pos; i++) {
            if (max>=i){
                max=Math.max(max,i+nums[i]);
                if (max>=pos){
                    return true;
                }
            }else {
                return false;
            }
        }
        return true;
    }
}
